css: Match state in siblings properly
authorBenjamin Otte <otte@redhat.com>
Wed, 13 Aug 2014 14:18:39 +0000 (16:18 +0200)
committerBenjamin Otte <otte@redhat.com>
Wed, 13 Aug 2014 14:51:16 +0000 (16:51 +0200)
Previously, we always returned the state flags of the original widget
and did not consider the siblings' pseudoclasses.

Testcase is attached.

gtk/gtkcssmatcher.c
testsuite/reftests/Makefile.am
testsuite/reftests/sibling-pseudoclasses.css [new file with mode: 0644]
testsuite/reftests/sibling-pseudoclasses.ref.ui [new file with mode: 0644]
testsuite/reftests/sibling-pseudoclasses.ui [new file with mode: 0644]

index d169c274cf33042ab5dc0ba93ead37245bcba31c..b734bfa3ea69e10e32d8cf901149f48546d7a305 100644 (file)
@@ -56,7 +56,13 @@ gtk_css_matcher_widget_path_get_previous (GtkCssMatcher       *matcher,
 static GtkStateFlags
 gtk_css_matcher_widget_path_get_state (const GtkCssMatcher *matcher)
 {
-  return gtk_widget_path_iter_get_state (matcher->path.path, matcher->path.index);
+  const GtkWidgetPath *siblings;
+  
+  siblings = gtk_widget_path_iter_get_siblings (matcher->path.path, matcher->path.index);
+  if (siblings && matcher->path.sibling_index != gtk_widget_path_iter_get_sibling_index (matcher->path.path, matcher->path.index))
+    return gtk_widget_path_iter_get_state (siblings, matcher->path.sibling_index);
+  else
+    return gtk_widget_path_iter_get_state (matcher->path.path, matcher->path.index);
 }
 
 static gboolean
index 8501c34ab674b41ab1fbf064b4db43e2da1492ef..9e04237682f164cd2111da4fca38428812aadc78 100644 (file)
@@ -334,6 +334,9 @@ testdata = \
        shorthand-entry-border.css \
        shorthand-entry-border.ref.ui \
        shorthand-entry-border.ui \
+       sibling-pseudoclasses.css \
+       sibling-pseudoclasses.ref.ui \
+       sibling-pseudoclasses.ui \
        simple.ref.ui \
        simple.ui \
        sizegroups-basics.css \
diff --git a/testsuite/reftests/sibling-pseudoclasses.css b/testsuite/reftests/sibling-pseudoclasses.css
new file mode 100644 (file)
index 0000000..52faf13
--- /dev/null
@@ -0,0 +1,3 @@
+:active + * {
+  color: tomato;
+}
diff --git a/testsuite/reftests/sibling-pseudoclasses.ref.ui b/testsuite/reftests/sibling-pseudoclasses.ref.ui
new file mode 100644 (file)
index 0000000..ef39a84
--- /dev/null
@@ -0,0 +1,46 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.18.1 -->
+<interface>
+  <requires lib="gtk+" version="3.12"/>
+  <object class="GtkWindow" id="window1">
+    <property name="can_focus">False</property>
+    <child>
+      <object class="GtkBox" id="box1">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <child>
+          <object class="GtkToggleButton" id="togglebutton1">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">True</property>
+            <property name="active">True</property>
+            <child>
+              <placeholder/>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="label1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="label" translatable="yes">I'm tomato.</property>
+            <attributes>
+              <attribute name="foreground" value="#ffff63634747"/>
+            </attributes>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>
diff --git a/testsuite/reftests/sibling-pseudoclasses.ui b/testsuite/reftests/sibling-pseudoclasses.ui
new file mode 100644 (file)
index 0000000..4c83b24
--- /dev/null
@@ -0,0 +1,43 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!-- Generated with glade 3.18.1 -->
+<interface>
+  <requires lib="gtk+" version="3.12"/>
+  <object class="GtkWindow" id="window1">
+    <property name="can_focus">False</property>
+    <child>
+      <object class="GtkBox" id="box1">
+        <property name="visible">True</property>
+        <property name="can_focus">False</property>
+        <property name="orientation">vertical</property>
+        <child>
+          <object class="GtkToggleButton" id="togglebutton1">
+            <property name="visible">True</property>
+            <property name="can_focus">True</property>
+            <property name="receives_default">True</property>
+            <property name="active">True</property>
+            <child>
+              <placeholder/>
+            </child>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">0</property>
+          </packing>
+        </child>
+        <child>
+          <object class="GtkLabel" id="label1">
+            <property name="visible">True</property>
+            <property name="can_focus">False</property>
+            <property name="label" translatable="yes">I'm tomato.</property>
+          </object>
+          <packing>
+            <property name="expand">False</property>
+            <property name="fill">True</property>
+            <property name="position">1</property>
+          </packing>
+        </child>
+      </object>
+    </child>
+  </object>
+</interface>